package com.base.caselib.presenter;

import android.app.Activity;

import com.base.caselib.bean.AskBean;
import com.base.caselib.view.AskRecordView;
import com.base.commonlib.base.presenter.BasePresenter;
import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.http.utils.CallBackImpl;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.disposables.Disposable;

/**
 * Created by weikailiang on 2019/10/29.
 */

public class AskRecordPresenter extends BasePresenter<AskRecordView>{
    public boolean mHasSaved;
    public AskRecordPresenter(AskRecordView view, Activity activity) {
        super(view, activity);
    }

    public void getPdf() {
        if(!mHasSaved)
        {
            mView.showMes("请先保存");
            return;
        }
    }
    public void getAskRecord(String caseId){
        mView.showPb_mes("正在初始化");
        Map<String,Object> params = new HashMap<>();
        params.put("caseId",caseId);
        Disposable disposable = RealNetWorkUtil.get()
                .method("api-case/punishCase/getContent")
                .params(params)
                .build().enqueue(AskBean.class, new CallBackImpl<AskBean>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.hidePb_mes();
                        mView.showMes(msg);
                    }

                    @Override
                    public void onNext(AskBean objects) {
                        mView.hidePb_mes();
                        mView.getAskRecordBean(objects);
                    }
                });
        mCompositeDisposable.add(disposable);
    }
    public void saveAskRecord(String caseId,String ask){
        mView.showPb_mes("正在提交数据");
        Map<String,String> params = new HashMap<>();
        params.put("caseId",caseId);
        params.put("investigationContent",ask);
        Disposable disposable = RealNetWorkUtil.postContent()
                .method("api-case/punishCase/saveContent")
                .content(params)
                .build().enqueue(String.class, new CallBackImpl<String>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.hidePb_mes();
                        mView.showMes(msg);
                    }

                    @Override
                    public void onNext(String objects) {
                        mHasSaved = true;
                        mView.hidePb_mes();
                        mView.showMes(objects);
                    }
                });
        mCompositeDisposable.add(disposable);
    }
}
